package com.kele.service.impl;

import com.kele.dao.UserDao;
import com.kele.domain.User;
import com.kele.service.BlogService;
import com.kele.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 赵奥林
 * @date 2021年05月10日 13:05
 * @Description
 */

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    //查询所有用户
    @Override
    public List<User> findAll(@Param("pageNum") int pageNum, @Param("dataNums") int dataNums) {
        return userDao.findAll( pageNum,dataNums);
    }

    //注册
    @Override
    public int insertUser(User user) {
       return userDao.insertUser(user);
    }

    /**
     * 用户登录
     * @param account
     * @param password
     * @return
     */
    @Override
    public User loginUser(String account,String password) {
        User user = userDao.loginUser(account, password);
        return user;
    }


    //用户注销（不是退出登录）
    @Override
    public void deleteAccount(Integer id,String password) {
        userDao.deleteAccount(id,password);
    }

    //用户修改密码
    @Override
    public int updateUserPassword(Integer id, String newPassword) {
        return userDao.updateUserPassword(id,newPassword);
    }

    //根据id查询用户名
    @Override
    public User queryUserById(Integer id) {
        return userDao.queryUserById(id);
    }





    //根据账号名查找用户
    @Override
    public User queryByAccount(String account) {
        return userDao.queryByAccount(account);
    }

    @Override
    public String queryPasswordByAccount(String account) {
        return userDao.queryPasswordByAccount(account);
    }

    //用户修改信息(根据账户) 或者管理员修改用户资料（账号除外）
    @Override
    public int updateUser(User user) {
        return userDao.updateUser(user);
    }

    //判断用户是否存在
    @Override
    public User checkAccount(String account) {
        return userDao.checkAccount(account);
    }



    //管理员添加用户
    @Override
    public User addUser(User user) {
        return userDao.addUser(user);
    }

    //管理员删除用户
    @Override
    public int deleteUser(Integer id) {
       return userDao.deleteUser(id);
    }

    @Override
    public User queryUserByEmail(String email) {
        User user = userDao.queryUserByEmail(email);
        if (user!=null){
            return user;
        }
        return null;
    }

    @Override
    public Integer updatePasswordByEmail(String email,String password) {
        return userDao.updatePasswordByEmail(email,password);
    }

    @Override
    public int subFollow(int id) {
        return userDao.subFollow(id);
    }

    @Override
    public int addFollow(int id) {
        return userDao.addFollow(id);
    }

    @Override
    public int addFans(int id) {
        return userDao.addFans(id);
    }

    @Override
    public int subFans(int id) {
        return userDao.subFans(id);
    }

    @Override
    public int findAllSize(String table,int flag) {
        return userDao.findAllSize(table,flag);
    }

    @Override
    public int checkNickName(String nickName) {
        return userDao.checkNickName(nickName);
    }

    @Override
    public int deleteList(Integer[] ids) {
        return userDao.deleteList(ids);
    }

    @Override
    public int setVip(Integer id,String paytime, int vip) {
        return userDao.setVip(id,paytime,vip);
    }

    @Override
    public List<User> selectAllFollow(Integer userid) {
        return userDao.selectAllFollow(userid);
    }

    @Override
    public List<User> selectAllFollows(Integer bloggerId) {
        return userDao.selectAllFollows(bloggerId);
    }

    @Override
    public List<User> fuzzy(String attribute) {
        return userDao.fuzzy(attribute);
    }
}
